#include <iostream>
using namespace std;

const int N=1e5+10;
int n,ans=-1e9-7;
int a[N];
int l,r,t;

void dfs(int dep,int sum)
{
    if(dep==n+1)
    {
        ans=max(sum,ans);
        return ;
    }
    int s=l;
    //cout<<l<<" "<<r<<" "<<dep<<" "<<sum<<endl;
    if(a[l]==a[dep])
        l=dep,dfs(dep+1,sum+a[dep]);
    else
        l=dep,dfs(dep+1,sum);
    l=s;
    s=r;
    if(a[r]==a[dep])
        r=dep,dfs(dep+1,sum+a[dep]);
    else
        r=dep,dfs(dep+1,sum);
    r=s;
    return ;
}

int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>t;
    while(t--)
    {
        cin>>n;
        l=0,r=0;
        for(int i=1;i<=n;i++)
            cin>>a[i];
        dfs(1,0);
        cout<<ans<<endl;
    }

    return 0;
}
